'use strict';


const db = uniCloud.database();
const dbCmd = db.command // 取指令

async function hotelDetail(event){
	// 获取hotel详情
	let hotelRus
	let {id} = event
	await db.collection('xinxuan_hotel').where({_id:id}).get().then((res)=>{
		hotelRus = res.data[0]
		hotelRus.serList = []
	});
	return new Promise((res,rej)=>{
		let i = 0
		function isEnd(){
			res({
				code: 0,
				msg:'',
				data: hotelRus
			})
		}
		// 获取服务详情
		hotelRus.serviceList.map(async (item)=>{
			 await db.collection('service').where({_id:item}).get().then((result)=>{
				 hotelRus.serList.push({
					 icon:result.data[0].imageUrl,
					 name:result.data[0].name
				 })
				 i++
				 if(i == hotelRus.serviceList.length){
					 console.log(123)
					 isEnd()
				 }
			 });
		})
	})
}

exports.main = hotelDetail;